<template>
	<view>
		<!-- 顶部导航栏 -->
		<view class="header">
			<x-status-bar></x-status-bar>
			<view class="flex-center-between header-navbar">
				<x-back-btn></x-back-btn>
				<view class="u-f-40 common-title">{{ lang_personal.extensionPerson }}</view>
				<view></view>
			</view>

			<!-- 分割线 -->
			<u-gap height="1" bgColor="rgba(0, 0, 0, 0.07)"></u-gap>
		</view>

		<view>
			<mescroll-body height="calc(100vh - 100rpx - var(--status-bar-height))" ref="mescrollRef"
				@init="mescrollInit" @down="downCallback" @up="upCallback">
				<view>
					<view>
						<view class="u-text-center u-p-t-40">
							<image src="@/static/image/personal/head_post.png" style=" width: 532rpx; height: 294rpx;"
								class="clear-flex"></image>

							<view class="flex-center-center u-m-t-30 u-f-40 u-lh-56 font-medio">
								<view>{{ lang_personal.totalGain }}:</view>
								<view class="flex-baseline">
									<view class="u-f-24">{{ lang_unit.money }}</view>
									<view>{{ dataInfo.totalAmount || 0 }}</view>
								</view>
							</view>

							<view v-if="dataInfo.headType && showTime"
								class="flex-center-center u-m-t-18 u-f-30 u-lh-42">
								<view class="color-grew">临时团长身份将在</view>
								<view class="font-bold" style="color: #FD1E43;">
									{{ dataInfo.tmpHeadEndTime }}
									<!-- <x-counttime :time="dataInfo.tmpHeadEndTime" format="H+:m+:s+"></x-counttime> -->
								</view>
								<view class="color-grew">后失效</view>
							</view>
						</view>
					</view>

					<!-- 列表 -->
					<view style="padding: 40rpx;">
						<view class="container">
							<view class="container-header u-p-t-28 u-p-b-18 u-f-40 u-lh-56 font-medio u-text-center">
								{{ lang_personal.totalExtension }}: {{ total || 0 }}{{ lang_unit.people }}</view>

							<view>
								<view v-for="(item, index) in dataList" :key="index"
									class="flex-center-between">
									<view class="u-m-t-38 u-p-b-22 flex-center">
									<view class="u-avatar-50 u-m-r-20" style="width: 82rpx; height: 82rpx;">
										<x-image :src="showImage(item.avatar, 'logo')"/>
									</view>
									<view class="flex-between flex-column">
										<view class="u-f-32 u-lh-44 font-medio">{{ item.nick || '' }}</view>
										<view class="u-m-t-4 u-f-20 u-lh-28 color-grew">
											{{ lang_personal.inviteDate }}：{{ dayjs(item.createTime).format('YYYY/MM/DD HH:mm:ss') }}
										</view>
									</view>
									</view>
					
									<view class="flex-baseline u-lh-28 font-medio">
										<view class="u-f-26">{{ lang_unit.money }}</view>
										<view class="u-f-36">{{ item.money || 0 }}</view>
									</view>
								</view>
							</view>
						</view>
					</view>
					
					<!-- 留空 -->
					<view style="height: 200rpx"></view>
				</view>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	import {
		userPromoteInfo,
		userInvitedUserPage
	} from '@/api/personal.js'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";

	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				dataInfo: {},

				total: 0,
				dataList: []
			}
		},
		computed: {
			showTime() {
				let { tmpHeadStartTime } = this.dataInfo
				if (!tmpHeadStartTime) {
					return
				}
				return (this.dayjs(tmpHeadStartTime).valueOf()) < this.dayjs().valueOf()
			}
		},
		// 获取类型
		onLoad({
			type
		}) {},
		methods: {
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				let node = this.$refs['mescrollRef']
				userInvitedUserPage({
					pageNumber: page.num,
					pageSize: page.size
				}).then(res => {
					node && node.mescroll.endSuccess(res.list.length);
					this.total = res.totalRow || 0
					if (page.num == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.dataList = this.dataList.concat(res.list); //追加新数据
				}).catch(() => {
					node && node.mescroll.endErr();
				})
			},
			downCallback() {
				let node = this.$refs['mescrollRef']
				node && node.mescroll.resetUpScroll()
				this.initInfo()
			},
			// 初始化详情
			initInfo() {
				userPromoteInfo({}).then((result) => {
					this.dataInfo = result
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		padding: 30rpx 40rpx;
		background-color: #F9F9F9;
		border-radius: 10rpx;

		&-header {
			border-bottom: 2rpx dashed #DADADA
		}
	}
</style>
